/**
 * JungoMobileWeb
 * DealDaoImpl.java
 * 
 * Copyright 2013 Teachizen
 * Written by cloudstick
 *	2013. 8. 11. first written.
 *
 * note:
 */
package com.jungo.web.dao.impl;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.jungo.web.bean.Deal;
import com.jungo.web.bean.Favorite;
import com.jungo.web.bean.Product;
import com.jungo.web.dao.DealDao;

/**
 * @author cloudstick
 *
 */
@Repository
public class DealDaoImpl extends SqlSessionDaoSupport implements DealDao {

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#getProductWithFavorite(com.jungo.web.bean.Favorite)
	 */
	@Override
	public List<Product> getProductByFavorite(Favorite favorite) {
		return getSqlSession().selectList("DealDao.getProductByFavorite", favorite);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#getFavoriteWithProduct(com.jungo.web.bean.Product)
	 */
	@Override
	public Favorite getFavoriteByProduct(Product product) {
		return getSqlSession().selectOne("DealDao.getFavoriteByProduct", product);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#getDealId()
	 */
	@Override
	public Integer getDealId() {
		return getSqlSession().selectOne("DealDao.getDealId");
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#setDeal(com.jungo.web.bean.Deal)
	 */
	@Override
	public void setDeal(Deal deal) {
		getSqlSession().insert("DealDao.setDeal", deal);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#getDeals(int)
	 */
	@Override
	public List<Deal> getDeals(int pid) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#updateFavoriteCount(int)
	 */
	@Override
	public void updateFavoriteCount(int pid) {
		getSqlSession().update("DealDao.updateFavoriteCount", pid);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#checkDuplicateDeal(com.jungo.web.bean.Deal)
	 */
	@Override
	public boolean checkDuplicateDeal(Deal deal) {
		Integer count = getSqlSession().selectOne("DealDao.checkDuplicateDeal", deal);
		return ( count > 0 ) ? false : true;
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#updateDealStatus(com.jungo.web.bean.Deal)
	 */
	@Override
	public void updateDealStatus(Deal deal) {
		getSqlSession().update("DealDao.updateDealStatus", deal);
	}

	/* (non-Javadoc)
	 * @see com.jungo.web.dao.DealDao#getDealByFavorite(int)
	 */
	@Override
	public Product getMatchedProductByFavorite(int fid) {
		return getSqlSession().selectOne("DealDao.getMatchedProductByFavorite", fid);
	}

}
